X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/blobdiff_plain/8534e46e400268c5ceffb3b14f02cef39eedae8f..3de51c6f55d304f038df1b77c8ab346e2a187fe1:/Super%20Polarity/Actors/Bullet.cs?ds=sidebyside diff --git a/Super Polarity/Actors/Bullet.cs b/Super Polarity/Actors/Bullet.cs new file mode 100644 index 0000000..d20289c --- /dev/null +++ b/Super Polarity/Actors/Bullet.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace SuperPolarity +{ + class Bullet : Actor + { + protected ParticleEngine particleEngine; + public int Power; + + public Bullet(SuperPolarity newGame) + : base(newGame) + { + } + + ~Bullet() + { + particleEngine = null; + } + + public override void Initialize(Texture2D texture, Vector2 position) + { + base.Initialize(texture, position); + BoxDimensions.X = 10; + BoxDimensions.Y = 10; + BoxDimensions.W = 10; + BoxDimensions.Z = 10; + MaxVelocity = 8; + InitBox(); + particleEngine = ParticleEffectFactory.CreateBullet(position); + } + + public override void Update(GameTime gameTime) + { + Velocity.X = (float)(MaxVelocity * Math.Cos(Angle)); + Velocity.Y = (float)(MaxVelocity * Math.Sin(Angle)); + + Power = 1; + + Position += Velocity; + UpdateBox(); + + particleEngine.Update(); + particleEngine.EmitterLocation = Position; + } + + public override void Draw(SpriteBatch spriteBatch) + { + base.Draw(spriteBatch); + particleEngine.Draw(spriteBatch); + } + + public override void Collide(Actor other, Rectangle collision) + { + if (Dying) { return; } + if (other.GetType().IsAssignableFrom(typeof(StandardShip))) + { + Die(); + return; + } + } + + protected override void Die() + { + ActorManager.CheckOut(this); + Renderer.CheckOut(this); + Parent.Children.Remove(this); + } + + public override void CleanUp() + { + base.CleanUp(); + this.particleEngine = null; + } + } +}